﻿@model CreateJiesuanModel
@{
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new CreateJiesuanModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}


<form id="S_Form" action="@Url.Action("create", "jiesuan")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" width="50%">
                <h5>
                    @ViewBag.Title，创建结算申请，标<em>*</em>号是必填或必选项。
                </h5>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">付款类型<em>*</em></td>
            <td>
                <select id="aDZ_JiesuanMaster.pay_type" name="aDZ_JiesuanMaster.pay_type">
                    <option value="1">货款（向供应商付款）</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">供应商账号模板<em>*</em></td>
            <td>
                <select id="supplierdetails_id" name="aDZ_JiesuanMaster.supplierdetails_id" onchange="showpayinfo()">
                    @{
                        dc = new Dictionary<string, string>();
                        dbcontext.ADZ_SupplierDetails.Where(t => t.is_del == 0 && t.audit_status == 1 && t.supplier_id == viewModel.aDZ_JiesuanMaster.supplier_id).ToList().ForEach(t =>
                        {
                            dc.Add(t.seq_id.ToString(), JiesuanBiz.Instance.GetSupplierDetailsName(t));
                        });
                    }
                    @HtmlPagerHelper.ShowSelectOpton(dc, viewModel.aDZ_JiesuanMaster.supplierdetails_id.ToString())
                </select>&nbsp;
            </td>
        </tr>
        <tr id="trPayInfo" style="display:;">
            <td></td>
            <td id="tdPayInfo">
                付款货币：<br />
                是否开票：           <br />
                付款渠道：           <br />
                收款方开户行：           <br />
                收款方银行账号：           <br />
                收款方银行开户名：           <br />
                公司账户：           <br />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">订单金额</td>
            <td>
                @viewModel.aDZ_JiesuanMaster.order_money
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">供货金额</td>
            <td>
                @viewModel.aDZ_JiesuanMaster.supply_money
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">付款金额</td>
            <td>
                <input type="text" name="aDZ_JiesuanMaster.jiesuan_money" style="width:300px;" value="@viewModel.aDZ_JiesuanMaster.jiesuan_money" />（@(MyEnumHelper.GetEnumItemDescription<CurrencyType>(viewModel.aDZ_JiesuanMaster.currency_type))）
            </td>
        </tr>

        <tr>
            <td width="6%" class="tableleft">备注</td>
            <td>
                <textarea name="aDZ_JiesuanMaster.remark" style="width:80%;" maxlength="2500" placeholder="" cols="4">@viewModel.aDZ_JiesuanMaster.remark</textarea>
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p>
                    <span id="spMsg"></span>
                </p>
                <button type="submit" class="btn btn-primary">提交</button> &nbsp;&nbsp;

                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>
        </tr>
    </table>

    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" width="50%">
                <h5>
                    结算订单明细
                </h5>
            </td>
        </tr>
    </table>
    <table class="table table-bordered table-hover definewidth m10">
        <thead>
            <tr>
                <th>收款方名称</th>
                <th>订单号</th>
                <th>订单日期</th>
                <th>付款类型</th>
                <th>付款货币</th>
                <th>是否含税</th>
                <th>付款渠道</th>
                <th>付款金额</th>
                <th>供货金额</th>
                <th>执行状态</th>
                <th>付款申请人</th>
                <th>备注</th>
                <th>申请时间</th>
                <th>驳回理由</th>
            </tr>
        </thead>
        @{
            var querylist = dbcontext.ADZ_JiesuanOrderDetails.Where(t => viewModel.cbx_last.Contains(t.seq_id.ToString())).ToList();
            var resultList = new List<WaitJiesuanModel>();
            if (querylist.Any())
            {
                querylist.ForEach(t =>
                {
                    WaitJiesuanModel model = new WaitJiesuanModel();
                    model.aDZ_JiesuanOrderDetails = t;
                    if (t.supplier_id > 0)
                    {
                        model.aDZ_SupplierMaster = dbcontext.ADZ_SupplierMaster.FirstOrDefault(x => x.supplier_id == t.supplier_id);
                    }
                    if (t.jiesuan_id > 0)
                    {
                        model.aDZ_JiesuanMaster = dbcontext.ADZ_JiesuanMaster.FirstOrDefault(x => x.jiesuan_id == t.jiesuan_id);
                    }
                    resultList.Add(model);
                });
            }
        }
        @if (resultList != null && resultList.Count != 0)
        {
            int index = 0;
            foreach (var m in resultList)
            {
                index++;
                <tr class="@HtmlPagerHelper.TrClass(index)">
                    <td>
                        <input type="hidden" name="cbx_last" value="@m.aDZ_JiesuanOrderDetails.seq_id" />
                        @m.aDZ_SupplierMaster.supplier_name
                    </td>
                    <td>@m.aDZ_JiesuanOrderDetails.order_no</td>
                    <td>@m.aDZ_JiesuanOrderDetails.order_time.ToString(2)</td>
                    <td>货款（向供应商结算）</td>
                    <td>
                        @(MyEnumHelper.GetEnumItemDescription<CurrencyType>(m.aDZ_JiesuanOrderDetails.currency_type))
                    </td>
                    <td> @(MyEnumHelper.GetEnumItemDescription<include_tax>(m.aDZ_JiesuanOrderDetails.include_tax))</td>
                    <td> @(MyEnumHelper.GetEnumItemDescription<SupplierPayChanner>(m.aDZ_JiesuanMaster.channel))</td>
                    <td>@m.aDZ_JiesuanOrderDetails.order_money.ToString("N2")</td>
                    <td>@m.aDZ_JiesuanOrderDetails.supply_money.ToString("N2")</td>
                    <td>
                        @(MyEnumHelper.GetEnumItemDescription<jiesuan_status>(m.aDZ_JiesuanOrderDetails.jiesuan_status))
                    </td>
                    <td>
                        @m.aDZ_JiesuanMaster.apply_username
                    </td>
                    <td>
                        @m.aDZ_JiesuanMaster.remark
                    </td>
                    <td>
                        @m.aDZ_JiesuanMaster.create_time.ToString(1)
                    </td>
                    <td>
                        @m.aDZ_JiesuanMaster.reject_reson
                    </td>
                </tr>
            }
            <tr>
                <td colspan="20"></td>
            </tr>
        }
    </table>
    <input type="hidden" name="aDZ_JiesuanMaster.supplier_id" value="@viewModel.aDZ_JiesuanMaster.supplier_id" />
</form>
<script>
    var rules = {
        'aDZ_JiesuanMaster.jiesuan_money': { required: true, IsBigThan0: true },
        'aDZ_JiesuanMaster.pay_type': { required: true },
        'aDZ_JiesuanMaster.supplierdetails_id': { required: true }
    };
    var messages = {
        //'aDZ_GoodsMaster.goods_unit': { required: '售卖单位必选' },
    };

    var validator = $('#S_Form').validate({
        errorLabelContainer: $("#errorContainer"),
        errorElement: "span",
        rules: rules,
        messages: messages,
        submitHandler: function (form) {
            $(form).ajaxSubmit(function (result) {
                ShowActionResult(result, function () {
                    $("#backid").click();
                });
            });
        }
    });

    function showpayinfo() {
        var supplierdetails_id = $("#supplierdetails_id").val();

        var url = "@Url.Action("GetpayInfo", "common")";
        var parameter = {
            supplierdetails_id: supplierdetails_id
        };
        $.post(url, parameter, function (result) {
            if (result) {
                var html = "";
                if (result.currency_type == @((int)CurrencyType.RMB))
                    html += "                付款货币：人民币<br />";
                if (result.currency_type == @((int)CurrencyType.Dollar))
                    html += "                付款货币：美金<br />";

                if (result.is_invoice ==  @((int)include_tax.HasTax))
                    html += "                是否开票：开票<br />";
                if (result.is_invoice ==  @((int)include_tax.NoTax))
                    html += "                是否开票：不开票<br />";
                
                if (result.channel ==  @((int)SupplierPayChanner.Bank)) {
                    html += "                付款渠道：银行转账<br />";
                    html += "                收款方开户行：" + result.bank_name + " " + result.branch_bank_name+"<br />";
                    html += "                收款方银行账号：" + result.bank_account_name +"<br />";
                    html += "                收款方银行开户名：" + result.bank_account +"<br />";
                }
                if (result.channel ==  @((int)SupplierPayChanner.Alipay)) {
                    html += "                付款渠道：支付宝转账<br />";
                    html += "                支付宝账号：" + result.alipay_account+"<br />";
                }
                if (result.channel ==  @((int)SupplierPayChanner.Weixin)) {
                    html += "                付款渠道：微信转账<br />";
                    html += "                微信账号：" + result.wechat_account+"<br />";
                }
                $("#tdPayInfo").html(html);
            }
        });
    }

    $(document).ready(function () {
        showpayinfo();
    });
</script>
